package cn.seecoder.ai.utils;

import cn.seecoder.ai.enums.MachineLearningAlgorithmEnum;
import cn.seecoder.ai.enums.MachineLearningAlgorithmTypeEnum;
import cn.seecoder.ai.exception.AIExternalException;

import java.util.Arrays;

/**
 * @author fanyanpeng
 * @date 2023/4/24 4:48
 */
public class MLAlgorithmHelper {


    public static MachineLearningAlgorithmTypeEnum getMachineLearningAlgorithmTypeEnum(MachineLearningAlgorithmEnum machineLearningAlgorithmEnum){
        MachineLearningAlgorithmTypeEnum[] algorithmTypeEnums = new MachineLearningAlgorithmTypeEnum[]{
                MachineLearningAlgorithmTypeEnum.CLASSIFICATION,
                MachineLearningAlgorithmTypeEnum.REGRESSION,
                MachineLearningAlgorithmTypeEnum.CLUSTERING
        };

        for(MachineLearningAlgorithmTypeEnum algorithmTypeEnum:algorithmTypeEnums){
            if(Arrays.stream(algorithmTypeEnum.getMachineLearningAlgorithmEnums()).anyMatch(i->i==machineLearningAlgorithmEnum)){
                return algorithmTypeEnum;
            }
        }

        //若没找到，抛出异常
        throw AIExternalException.machineLearningAlgorithmTypeNotFound();
    }

}
